home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung 2
/
Power-Programmierung CD 2 (Tewi)(1994).iso
/
gnu
/
gnulib
/
sipp
/
doc
/
sipp.1
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
GNU Info File
|
1994-02-16
|
48.5 KB
|
1,189 lines
This is Info file sipp, produced by Makeinfo-1.55 from the input file
sipp.tex.
Copyright (C) 1992 Jonas Yngvesson, Inge Wallin
File: sipp, Node: Top, Prev: (dir), Up: (dir)
This Info manual describes SIPP, a 3D rendering library. SIPP can
be used for creating 3-dimensional scenes and rendering them using a
scan-line z-buffer algorithm. A scene is built up of objects which can
be transformed with rotation, translation and scaling. The objects form
hierarchies where each object can have arbitrarily many subobjects and
subsurfaces. A surface is a number of connected polygons which are
rendered with either Phong, Gouraud or flat shading. An image can also
be rendered as a line drawing of the polygon edges without any shading
at all.
* Menu:
* License information:: Information about terms for copying SIPP.
* What is SIPP?:: An overview of SIPP.
* Installation:: How to install SIPP on your system.
* Getting started:: Tutorial introduction.
* Basic concepts:: Some basic concepts used in SIPP.
* Initializations:: Necessary and optional initializations.
* Creating objects:: How to build and install objects.
* Transformations:: Transformations of objects.
* Lights:: How to lit the stage.
* Shadows:: How to create good looking shadows.
* Viewpoint and cameras::Specifying viewing parameters.
* Rendering:: The different rendering variants available.
* Shaders:: Issues regarding shading functions for SIPP
* Object primitives:: Object primitives included in the library.
* Future enhancements:: Possible future enhancements of SIPP.
* Reporting bugs:: Where do you report a bug you have found?
* Concept index:: Index over important concepts in SIPP.
* Function index:: Index over the available functions in SIPP.
File: sipp, Node: License information, Next: What is SIPP?, Prev: Top, Up: Top
GNU GENERAL PUBLIC LICENSE
**************************
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
========
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software,
and (2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
1. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work
based on the Program" means either the Program or any work
containing the Program or a portion of it, either verbatim or with
modifications. Each licensee is addressed as "you".
2. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep
intact all the notices that refer to this General Public License
and to the absence of any warranty; and give any other recipients
of the Program a copy of this General Public License along with
the Program. You may charge a fee for the physical act of
transferring a copy.
3. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of
Paragraph 1 above, provided that you also do the following:
* cause the modified files to carry prominent notices stating
that you changed the files and the date of any change; and
* cause the whole of any work that you distribute or publish,
that in whole or in part contains the Program or any part
thereof, either with or without modifications, to be licensed
at no charge to all third parties under the terms of this
General Public License (except that you may choose to grant
warranty protection to some or all third parties, at your
option).
* If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the simplest and most usual way, to print
or display an announcement including an appropriate copyright
notice and a notice that there is no warranty (or else,
saying that you provide a warranty) and that users may
redistribute the program under these conditions, and telling
the user how to view a copy of this General Public License.
* You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or
its derivative) on a volume of a storage or distribution medium
does not bring the other work under the scope of these terms.
4. You may copy and distribute the Program (or a portion or
derivative of it, under Paragraph 2) in object code or executable
form under the terms of Paragraphs 1 and 2 above provided that you
also do one of the following:
* accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
* accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal
charge for the cost of distribution) a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Paragraphs 1 and 2 above; or,
* accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative
is allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for
making modifications to it. For an executable file, complete
source code means all the source code for all modules it contains;
but, as a special exception, it need not include source code for
modules which are standard libraries that accompany the operating
system on which the executable file runs, or for standard header
files or definitions files that accompany that operating system.
5. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public
License. Any attempt otherwise to copy, modify, sublicense,
distribute or transfer the Program is void, and will automatically
terminate your rights to use the Program under this License.
However, parties who have received copies, or rights to use
copies, from you under this General Public License will not have
their licenses terminated so long as such parties remain in full
compliance.
6. By copying, distributing or modifying the Program (or any work
based on the Program) you indicate your acceptance of this license
to do so, and all its terms and conditions.
7. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program
subject to these terms and conditions. You may not impose any
further restrictions on the recipients' exercise of the rights
granted herein.
8. The Free Software Foundation may publish revised and/or new
versions of the General Public License from time to time. Such
new versions will be similar in spirit to the present version, but
may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies a version number of the license which applies to
it and "any later version", you have the option of following the
terms and conditions either of that version or of any later
version published by the Free Software Foundation. If the Program
does not specify a version number of the license, you may choose
any version ever published by the Free Software Foundation.
9. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the
author to ask for permission. For software which is copyrighted
by the Free Software Foundation, write to the Free Software
Foundation; we sometimes make exceptions for this. Our decision
will be guided by the two goals of preserving the free status of
all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
10. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
SERVICING, REPAIR OR CORRECTION.
11. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY
MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU
OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY
OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Applying These Terms to Your New Programs
=========================================
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
ONE LINE TO GIVE THE PROGRAM'S NAME AND A BRIEF IDEA OF WHAT IT DOES.
Copyright (C) 19YY NAME OF AUTHOR
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper
mail.
If the program is interactive, make it output a short notice like
this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19YY NAME OF AUTHOR
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or
your school, if any, to sign a "copyright disclaimer" for the program,
if necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
SIGNATURE OF TY COON, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
File: sipp, Node: What is SIPP?, Next: Installation, Prev: License information, Up: Top
What is SIPP?
*************
SIPP is a library for creating 3-dimensional scenes and rendering
them using a scan-line z-buffer algorithm. A scene is built up of
objects which can be transformed with rotation, translation and
scaling. The objects form hierarchies where each object can have
arbitrarily many subobjects and subsurfaces. A surface is a number of
connected polygons which are rendered with either Phong, Gouraud or
flat shading. An image can also be rendered as a line drawing of the
polygon edges without any shading at all.
The library also provides 3-dimensional texture mapping with
automatic interpolation of texture coordinates. Simple anti-aliasing
can be performed through oversampling. The scene can be illuminated by
an arbitrary number of lightsources. These lightsources can be of three
basic types: directional, point or spotlight. Light from spotlights can
cast shadows.
It is possible to create several virtual cameras, and then specify
one of them to use when rendering the image.
A major feature in SIPP is the ability for a user to provide his own
shading function for a surface. This makes it easy to experiment with
various shading models and to do special effects. A basic shading
algorithm is provided with the library, and also a package of other,
more special shaders.
Images can be rendered directly onto a file in the Portable Pixmap
format (ppm) or, for line images, Portable Bitmap, (pbm) or, with a
function defined by the user, into anything that it is capable of
plotting a pixel (or drawing a line), e.g. a window in a window system
or even a plotter file.
The object creation functions in SIPP are on a rather low level so to
make it easier to build scenes, a set of object primitives, like sphere,
cylinder, prism etc., is included.
* Menu:
* Authors:: Authors of SIPP.
* Archives:: Where can I get a copy of SIPP?
File: sipp, Node: Authors, Next: Archives, Up: What is SIPP?
Authors of SIPP
===============
The following persons have written or contributed to SIPP.
* Jonas Yngvesson wrote most of the otherwise unattributed functions
in SIPP as well as most of the documentation.
* Inge Wallin wrote the geometric functions, some object primitives,
pixmap functions, several demonstration programs and the rest of
the documentation.
* David Jones provided the code for the prism and cone primitives.
* Jon Buller wrote the noise and Dnoise functions (not specifically
for SIPP though, they were posted on the net).
* Several other people have aided the development by reporting bugs,
suggested enhancements, etc. etc. I will not mention any names,
you know who you are.
File: sipp, Node: Archives, Prev: Authors, Up: What is SIPP?
Where can I get SIPP?
=====================
There will probably be a number of sites archiving SIPP. Currently
the latest release can always be fetched via anonymous ftp from
`isy.liu.se', (IP no. 130.236.1.3) in the directory `pub/sipp'.
Two older versions (2.0 and 2.1) have been posted to
comp.sources.misc. They are in Volume 16 and Volume 21 respectively
and should be on any site that archives that group.
File: sipp, Node: Installation, Next: Getting started, Prev: What is SIPP?, Up: Top
Installation
************
This section describes the installation of the SIPP rendering
library. You should install not only the library itself, but also the
on-line documentation so that your users will know how to use it. You
can create typeset documentation from the file `sipp.texinfo' as well
as an on-line Info file. The following steps are also described in the
file `INSTALL' in the directory `sipp-3.0'.
* Menu:
* Library installation:: How to install SIPP on your system.
* Info manual installation:: How to install the Info manual.
* Typeset manual installation:: How to create typeset documentation about SIPP.
File: sipp, Node: Library installation, Next: Info manual installation, Up: Installation
Installation of the SIPP library
================================
Edit the file `Makefile' to reflect the situation at your site. The
things you might have to change are clearly marked in the beginning of
that file. They are also described below.
* The `NOVOID' definition should be used if the C compiler on your
system does not understand the type `void'.
* If the C library on your system does not contain the functions
`memcpy()' or `memset()', or the include file `memory.h' does not
exist, you should use the `NOMEMCPY' definition.
* If your system does not support the `alloca()' function, the
`ALLOCA' definition should be used. This will cause SIPP to use the
portable version of `alloca()' available from the GNU project.
* The definitions of `LIBDIR', `INCLUDEDIR', `MANDIR' and `MANEXT'
determines where in your file hierarchy SIPP will be installed.
`LIBDIR' is the directory where the final library file
(`libsipp.a') will be placed. When a program that uses SIPP is
linked, this directory should be in the path where the linker
looks for libraries, either direct or with the aid of the `-L'
switch. `INCLUDEDIR' is the directory where the includefiles
necessary to use SIPP will be placed. When a program that uses
SIPP is compiled, this directory should be in the path where the
compiler searches for include files, either direct or with the aid
of the `-I' switch. `MANDIR' is the directory in which to place
the UNIX style `man' page provided with SIPP. `MANEXT' determines
what extension that manual file will get.
Apart from these SIPP specific definitions, the usual C compiler and
flags to this compiler must of course be set to values suitable on your
system.
The only other item, apart from the `Makefile', is a definition in
the includefile `sipp.h' in the `libsipp' directory. In this file a
macro called `RANDOM()' is defined. If your system does not have the
`drand48()' function, you must change this definition. The macro should
return a random floating point number in the range (-1, 1).
By just typing `make' in the `sipp-3.0' directory, the library and
the demonstration programs will be compiled. The library is not
installed, but only compiled in place.
By typing `make library', the library will be compiled in place but
the demonstration programs will not.
Typing `make demos' will compile the demonstration programs only.
Since the demos require it, however, the library will also be compiled
if it was not done before.
Finally, typing `make install' will compile the library if it was
not done before, and copy that, the include files and the manual pages
to their appropriate places.
File: sipp, Node: Info manual installation, Next: Typeset manual installation, Prev: Library installation, Up: Installation
Installation of the on-line Info manual.
========================================
1. Create the Info files `sipp', `sipp-1', `sipp-2' and so on from
`sipp.texinfo'. If you have the `makeinfo' program, you can do
this by running it on `sipp.texinfo'. Otherwise you can do it
with emacs by running these steps:
1. Read `sipp.texinfo' into an emacs buffer.
2. Type ``M-X texinfo-format-buffer''
3. Save the newly created Info file `sipp', `sipp-1', `sipp-2'
and so on .
2. Move the Info file `sipp', `sipp-1', `sipp-2' and so on to the
standard Info directory. Usually this is `/usr/gnu/emacs/info' or
something similar. (See step 3 above).
3. Edit the file `dir' in the info directory and enter one line to
contain a pointer to the Info file `sipp'. The line can, for
instance, look like this:
* SIPP: (sipp). 3D rendering library.
File: sipp, Node: Typeset manual installation, Prev: Info manual installation, Up: Installation
How to make typeset documentation from sipp.texinfo
===================================================
You can also make a typeset manual from the file `sipp.texinfo'. To
do this, you must have the TeX text formatting program installed. Just
follow these steps:
1. If the file `texinfo.tex' is not properly installed in the path
given by the environment variable TEXINPUTS, get it and put it in
the same directory as `sipp.texinfo' (the `doc' directory of
SIPP). This file contains macros used by the TeX text formatting
program to produce typeset output from a texinfo file. You can get
this from, e.g., `prep.ai.mit.edu' in the US or from `isy.liu.se'
in Europe.
2. Run TeX by typing ``tex sipp.texinfo''. You might need to do this
twice to get all cross references correct. If you have the
`texindex' program, you can create a sorted index by typing
``texindex sipp.cp sipp.fn'' between the two TeX passes. If you
don't do this, you still get a typeset manual, but you will not
get the index.
3. Convert the resulting device independent file `sipp.dvi' to a form
which your printer can output and print it. If you have a
postscript printer there is a program, `dvi2ps', which can do
this. There is also a program which comes together with TeX,
`dvips', which you can use.
File: sipp, Node: Getting started, Next: Basic concepts, Prev: Installation, Up: Top
Getting started
***************
This chapter will be a small introduction of SIPP. We will go through
the steps of creating a simple scene and then enhance it with some
special effects. No specific details about the functions we use will be
explained, they can be found in other parts of this manual.
The first two things in a program using SIPP should be inclusion of
`sipp.h' and a call to `sipp_init()'. Then we can start using the
functions in SIPP to create a scene:
#include <stdio.h>
#include <sipp.h>
#include <primitives.h>
main()
{
FILE *image_fd;
Object *sphere;
Surf_desc sphere_surface;
sipp_init();
sphere_surface.ambient = 0.4;
sphere_surface.specular = 0.6;
sphere_surface.c3 = 0.1;
sphere_surface.color.red = 0.70; /* firebrick red */
sphere_surface.color.grn = 0.13;
sphere_surface.color.blu = 0.13;
sphere_surface.opacity.red = 1.0; /* Totally opaque */
sphere_surface.opacity.grn = 1.0;
sphere_surface.opacity.blu = 1.0;
sphere = sipp_sphere(2.0, 40, &sphere_surface, basic_shader, WORLD);
object_add_subobj(sipp_world, sphere);
lightsource_create(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, LIGHT_DIRECTION);
camera_params(sipp_camera, 0.0, 10.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.4);
image_fd = fopen("ex1.ppm", "w");
render_image_file(400, 400, image_fd, PHONG, 1);
}
If the program is stored in a file called `ex1.c' we can create an
executable program with the following command line:
cc -o ex1 ex1.c -lsipp -lm
When run, the program will create a PPM-file containing a 400x400
image of a red sphere lit by a single lightsource.
In the program we are going through the following steps: First we
initialize the library with a call to `sipp_init()'. Next we fill in a
description of surface properties in the kind of structure used in
SIPP's basic internal shader. We then create a sphere that will be
shaded with the basic shader using the previously defined surface
properties and tell SIPP to install this sphere among the objects that
should be considered when rendering. We create a lightsource and define
where the camera is and where it is looking. Last we open a file and
tell SIPP to render the scene into that file.
Enhancing the scene
===================
A single red sphere is not a very exciting image so we will now
enhance the image with some more interesting effects. We will put a
wooden floor under the sphere and exchange the lightsource for a
spotlight that will cast a shadow of the sphere onto the floor. The
floor is created as a simple block and we use the wood shader supplied
in the library. There will be rather high frequencies in the wood
pattern so we will render the image with some oversampling to make it
look better. The code looks like this:
#include <stdio.h>
#include <sipp.h>
#include <primitives.h>
#include <shaders.h>
main()
{
FILE *image_fd;
Object *sphere;
Object *floor;
Surf_desc sphere_surface;
Wood_desc floor_surface;
sipp_init();
sipp_shadows(TRUE, 600);
sphere_surface.ambient = 0.5;
sphere_surface.specular = 0.6;
sphere_surface.c3 = 0.1;
sphere_surface.color.red = 0.70; /* firebrick red */
sphere_surface.color.grn = 0.13;
sphere_surface.color.blu = 0.13;
sphere_surface.opacity.red = 1.0; /* Totally opaque */
sphere_surface.opacity.grn = 1.0;
sphere_surface.opacity.blu = 1.0;
sphere = sipp_sphere(2.0, 40, &sphere_surface, basic_shader, WORLD);
object_add_subobj(sipp_world, sphere);
floor_surface.ambient = 0.5;
floor_surface.specular = 0.0;
floor_surface.c3 = 0.99;
floor_surface.scale = 3.0;
floor_surface.base.red = 0.770; /* Very light brown */
floor_surface.base.grn = 0.568;
floor_surface.base.blu = 0.405;
floor_surface.ring.red = 0.468; /* Darker brown */
floor_surface.ring.grn = 0.296;
floor_surface.ring.blu = 0.156;
floor = sipp_block(20.0, 20.0, 1.0, &floor_surface, wood_shader,
WORLD);
object_move(floor, 0.0, 0.0, -2.5); /* Place it under the sphere */
object_add_subobj(sipp_world, floor);
spotlight_create(10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 40.0,
1.0, 1.0, 1.0, SPOT_SOFT, TRUE);
camera_params(sipp_camera, 0.0, 10.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.4);
image_fd = fopen("ex2.ppm", "w");
render_image_file(400, 400, image_fd, PHONG, 2);
}
File: sipp, Node: Basic concepts, Next: Initializations, Prev: Getting started, Up: Top
Basic concepts
**************
This chapter introduces and briefly explains some of the basic
concepts used in SIPP. They will later be used in this manual without
further explanation.
* Menu:
* Polygons:: What kind of polygons are handled.
* Surfaces:: What is a surface.
* Objects:: What is an object.
* Texture coordinates:: What is texture coordinates.
* Shading functions:: What is a shading function.
* Surface descriptions::What is a surface description.
* Datatypes:: Datatypes defined by SIPP.
File: sipp, Node: Polygons, Next: Surfaces, Up: Basic concepts
Polygons
========
SIPP can actually only render polygons, so everything else must be
built from those. SIPP can handle planar polygons without holes, either
convex or concave. The polygons have a defined front and back side, and
which is which is defined by the order in which the polygon vertices are
given. Vertices must be given counterclockwise when looking at the
front side of the polygon.
File: sipp, Node: Surfaces, Next: Objects, Prev: Polygons, Up: Basic concepts
Surfaces
========
Surfaces are the first step above polygons in the object hierarchy
supported by SIPP. A surface is a collection of polygons that is shaded
by the same shader (*Note Shading functions::) using the same surface
description (*Note Surface descriptions::). A pointer to that shader and
surface description is stored in the surface. If polygons within a
surface share vertices, the surface normal will be interpolated across
the polygons at rendering time, to create the impression of a smooth
surface.
File: sipp, Node: Objects, Next: Texture coordinates, Prev: Surfaces, Up: Basic concepts
Objects
=======
Objects are the highest level in the object hierarchy. An object is a
collection of surfaces and/or other objects, which are then called
subobjects. Object trees can be built to arbitrary depths.
Transformations can be applied to objects and if an object has
subobjects the transformation will propagate recursively down the object
tree. Every object has its current transformation relative to its
parent object stored in a transformation matrix which can be read and
written.
There is a predefined object called `sipp_world'. When SIPP renders
a scene it always starts in this object, so all objects that are to be
rendered must be subobjects (or subsubobjects etc.) to it. The world
object can be transformed like any other object.
File: sipp, Node: Texture coordinates, Next: Shading functions, Prev: Objects, Up: Basic concepts
Texture coordinates
===================
At each polygon vertex it is possible to specify up to three floating
point numbers called texture coordinates. These numbers are linearly
interpolated across the polygon and sent to the shader (*Note Shading
functions::) at rendering time. It is up to the implementor of the
shader to decide what to use them for. Texture coordinates are not
affected by object transformations.
File: sipp, Node: Shading functions, Next: Surface descriptions, Prev: Texture coordinates, Up: Basic concepts
Shading functions
=================
Every surface (*Note Surfaces::) in a scene has a shading function
(or shader) associated with it. The shader is a regular C function,
with a well defined interface, which is called for every pixel in the
surface when it is rendered. SIPP supplies the shader with enough
information for it to do a shading calculation, i.e. decide what color
that particular pixel should have. The shader is also responsible for
deciding the opacity of the surface. Besides the information supplied
by SIPP (world position, lightsources, texture coordinates, etc.), the
shader also gets a surface description (*Note Surface descriptions::)
which the user has defined.
File: sipp, Node: Surface descriptions, Next: Datatypes, Prev: Shading functions, Up: Basic concepts
Surface descriptions
====================
Every surface (*Note Surfaces::) has a description of its surface
properties. These properties can be e.g. color, material, opacity, etc.
Exactly what information is stored depends on which shader (*Note
Shading functions::) is used for shading the surface. The exact
representation of this information is entirely up to the shader
implementor.
File: sipp, Node: Datatypes, Prev: Surface descriptions, Up: Basic concepts
Datatypes
=========
The include file `sipp.h' defines several datatypes that are used
when working with SIPP. We will describe them briefly here and also give
the definitions for those that a user might need to access.
* `bool'
A boolean type which can have the value `TRUE' or `FALSE'.
* `Object'
This is an abstract data type holding information about an object.
Functions that creates objects returns pointers to `Object' and all
functions that operate on objects, e.g. transformations, take such
pointers as parameters.
* `Surface'
Similar to `Object' but contains information about a surface. The
user only needs to handle pointers to this type also.
* `Color'
This is a structure with three members describing a color in
RGB-space. Each member is a double and should have a value in the
range [0, 1].
typedef struct {
double red;
double grn;
double blu;
} Color;
* `Vector'
Structure defining a 3-D vector. *Note Vector operations:: for more
detailed information.
typedef struct {
double x;
double y;
double z;
} Vector;
* `Transf_mat'
A transformation matrix is used in every object to hold its current
transformation. The matrix is stored as a 4x3 matrix instead of a
complete 4x4 matrix in order to save space. *Note Matrix
operations:: for more detailed information.
typedef struct {
double mat[4][3];
} Transf_mat;
* `Camera'
`Camera' is a structure holding a virtual camera. All functions
involved work with pointers to this type. SIPP provides a
predefined `Camera' and a pointer to it called `sipp_camera'. This
camera is the default viewpoint used when rendering a scene.
* `Lightsource'
This structure hold information about a lightsource. Two members
in the struct are of interest to users writing their own shaders.
Color color;
and
Lightsource *next;
`color' decides the color of the light emitted from the lightsource
and `next' points to the next lightsource defined in the scene (or
NULL). *Note Writing your own shaders:: for a description of how
to use this information.
* `Surf_desc'
This is the surface description (*Note Surface descriptions::) for
the internal shader, `basic_shader()' (see *Note The basic
shader::). It has the following definition:
typedef struct {
double ambient;
double specular;
double c3;
Color color;
Color opacity;
} Surf_desc;
* `ambient' is a number in the range [0, 1] specifying how much
of the surface color that is visible when the object is not
lit by any lightsource.
* `specular' is a number in the range [0, 1] specifying how much
light that is reflected in a specular highlight on the
surface.
* `c3' is also a number in the range [0, 1]. It specifies how
"shiny" the surface is. 0 means a very shiny surface while 1
indicates a rather dull one.
* `color' is simply the color of the surface.
* `opacity' specifies how opaque the surface is. This is stored
as a color to allow different opacities for the different
color bands. The values should be in the range [0, 1] with 1
indicating a completely opaque object and 0 a completely
transparent (invisible) one.
File: sipp, Node: Initializations, Next: Creating objects, Prev: Basic concepts, Up: Top
Initializations
***************
Before using any of the functions, SIPP needs to be initialized.
Initialization is done with a call to the following function:
void
sipp_init()
Apart from initializations, some default settings are created:
* Backfacing polygons are culled.
* Background color is black.
* No shadows are cast.
* The camera is placed in (0 0 10), looking at the origin and with
the world y-axis as the up-axis. `sipp_init()' takes no parameters
There are also some functions that determine various global behavior
of SIPP. These functions can be called at any time:
void
sipp_background(red, green, blue)
double red;
double green;
double blue;
This function sets the background color in the rendered image. The
parameters are doubles in the range [0, 1]. The default value (set by
`sipp_init()') is black.
void
sipp_show_backfaces(flag)
bool flag;
Normally SIPP checks if a polygon is facing away from the viewpoint
and if that is the case, the polygon is not considered in the rendering.
There are times when this is not desirable. If one have a database of
polygons with inconsistent orientations (see *Note Polygons::), it is
necessary to render all polygons in it. There are also cases when
objects have holes and backfacing polygons are visible through that
hole. If `flag' is `TRUE' SIPP will render all polygons, if `flag' is
`FALSE' (default), backfacing polygons will be culled.
void
sipp_shadows(flag, size)
bool flag;
int size;
This function tells SIPP if it objects should cast shadows. When
`flag' is `TRUE' shadows are cast. The default is not to do it. Only
some types of lightsources are capable of producing shadows and it is
possible to turn that ability on and off for each such lightsource
(*Note Lights::). SIPP uses a technique called depth maps to do shadows
(*Note Shadows::). It is a kind of texture mapping and the size of the
depth maps are defined by the parameter `size'. As a rule of thumb one
could say that the depth maps should be at least as large as the image
itself but this may vary from case to case.
A word of warning: Rendering images with shadows requires very large
amounts of memory and takes considerably longer time than doing it
without them.
File: sipp, Node: Creating objects, Next: Transformations, Prev: Initializations, Up: Top
Creating objects
****************
This chapter describes how to build SIPP objects from polygons and
up. In the library there are also a number of functions that create
complete objects on a higher level (see *Note Object primitives::).
Those functions all use the low level tools described here.
* Menu:
* Creating polygons and surfaces:: The lowest levels.
* Building objects:: Objects and hierarchies of them.
* Duplicating objects:: More instances of old objects.
File: sipp, Node: Creating polygons and surfaces, Next: Building objects, Up: Creating objects
Creating polygons and surfaces
==============================
To build polygons and surfaces, SIPP uses two stacks, a vertex stack
and a polygon stack. Polygons are created by pushing vertices onto the
vertex stack and then calling a function that creates a polygon from
these vertices and push this newly created polygon onto the polygon
stack. When a number of polygons have been defined they can then be
combined into a surface.
The order in which vertices are pushed are important because this
determines the front and the back face of the polygon. Vertices should
be pushed in counterclockwise order when looking at the front face of
the polygon.
Note also that if polygons share vertices, these vertices should be
pushed for each polygon. SIPP looks up shared vertices automagically.
The following functions are used in the described process:
void
vertex_push(x, y, z)
double x, y, z;
Push a vertex onto the vertex stack.
void
vertex_tx_push(x, y, z, u, v, w)
double x, y, z;
double u, v, w;
Push a vertex with texture coordinates defined by (u, v, w) onto the
vertex stack. Calls to `vertex_push()' and `vertex_tx_push()' should
not be mixed within a polygon since that would make texture
interpolation to produce garbage. `vertex_push()' gives the vertex
texture coordinates (0 0 0).
void
polygon_push()
Takes all vertices currently on the vertex stack and creates a
polygon from them. The new polygon is pushed onto the polygon stack and
the vertex stack is emptied.
Surface *
surface_basic_create(ambient, red, green, blue, specular, c3,
opred, opgreen, opblue)
double ambient;
double red, green, blue;
double specular;
double c3;
double opred, opgreen, opblue;
Takes all polygons currently on the polygon stack, creates a surface
from them and returns a pointer to the new surface. The created surface
will be shaded with the basic shading function `basic_shader()' and the
arguments to `surface_basic_create()' are the values that will be
placed in the surface description, which for `basic_shader()' is of
type `Surf_desc'(see *Note Basic concepts:: and *Note Shaders::).
Surface *
surface_create(surface_desc, shader)
void *surface_desc;
Shader *shader;
Takes all polygons currently on the polygon stack, creates a surface
from them and returns a pointer to the new surface. The created surface
will be shaded with the shading function `shader' using the surface
description pointed to by `surface_desc' (see *Note Shaders::).
void
surface_basic_shader(surface, ambient, red, green, blue, specular, c3,
opred, opgreen, opblue)
Surface *surface;
double ambient;
double red, green, blue;
double specular;
double c3;
double opred, opgreen, opblue;
This function is used when a previously created surface should be
changed so that it is shaded with `basic_shader()'. This function can
also be used to set new values in the surface description if `surface'
is already shaded with `basic_shader()'.
void
surface_set_shader(surface, surface_desc, shader)
Surface *surface;
void *surface_desc;
Shader *shader;
This function is used when a previously created surface should be
changed so that it is shaded with another shader than the one specified
at creation time.
File: sipp, Node: Building objects, Next: Duplicating objects, Prev: Creating polygons and surfaces, Up: Creating objects
Building objects
================
An object in SIPP is a more abstract concept than surfaces and
polygons. It is a general "container" which can hold several surfaces
and also several other objects, which are then called subobjects. Such
hierarchies, or trees, of objects can be built to arbitrary depths. When
an object is transformed in some way, the transformation is propagated
down to all objects below it in the tree.
When SIPP renders a scene it begins in the predefined object
`sipp_world' and recursively traverses the tree under it, rendering all
objects it finds. This means that it is perfectly possible to create
objects that will not be rendered. For an object to be rendered it must
be installed somewhere in the tree below `sipp_world'.
To build objects and object trees the following functions are
provided:
Object *
object_create()
This function creates a new object and returns a pointer to it. The
new object contains no surfaces or subobjects, and is not installed in
any tree.
void
object_delete(object)
Object *object;
Delete an object. Release all memory occupied by an object, its
surfaces and its subobjects. This operation is only possible to do on a
top level object, i.e. an object that is not a subobject to any other
object. SIPP keeps track of internal references, and if some parts of
the tree below `object' are referenced from other objects (see *Note
Duplicating objects::), those parts are not deleted. It is not possible
to delete `sipp_world'.
void
object_add_surface(object, surface)
Object *object;
Surface *surface;
Install a surface in an object.
void
object_sub_surface(object, surface)
Object *object;
Surface *surface;
Remove a surface from an object.
void
object_add_subobj(object, subobject)
Object *object;
Object *subobject;
Install `subobject' as a subobject in `object'. Any transformations
of `subobject' will now be performed relative the local coordinate
system in `object'.
A word of warning: There is no detection of "circular lists" in SIPP.
This means that if an object is installed as a subobject in an object
that is already below it in the tree, SIPP will go into eternal
recursion and crash when it tries to render the scene.
void
object_sub_subobj(object, subobject)
Object *object;
Object *subobject;
Remove `subobject' as a subobject in `object'. If an object is to be
deleted, this function must be used first to remove it from its parent
object(s).
File: sipp, Node: Duplicating objects, Prev: Building objects, Up: Creating objects
Duplicating objects
===================
If a complicated object has been built, it is often convenient to be
able to copy and reuse it. SIPP supports three levels of copying object
hierarchies:
Object *
object_instance(object)
Object *object;
Create a new instance of an object and return a pointer to it. This
is the "shallowest" version of object copy in SIPP. It only creates a
copy of the top level object, pointed to by `object', and let the new
instance reference the same surfaces and subobjects as the original.
This saves space but has the property that if a subobject of one of the
instances are changed in some way (transformed, new subobjects, etc.)
the same change will appear in the other. The new object will have the
identity matrix as its transformation matrix.
Object *
object_dup(object)
Object *object;
This version of object duplication copies not only the top level
object, but also all the subobjects recursively. All copied objects in
the tree will reference the same surfaces though, so even if object
changes will be unique in the two copies, surface changes (new color,
new shader, etc.) in one copy will affect both. The new object will
have the identity matrix as its transformation matrix.
Object *
object_deep_dup(object)
Object *object;
Copy a complete object tree, objects, surfaces and all. The new
object will have the identity matrix as its transformation matrix.
File: sipp, Node: Transformations, Next: Lights, Prev: Creating objects, Up: Top
Transformations
***************
All objects can be transformed with the usual homogeneous
transformations: scaling, translation and rotation. The transformation
is stored in a transformation matrix for each object. This matrix can
also be read and written directly.
The same transformations that can be applied to objects can also be
applied to the matrices directly. There is also a vector type defined
and a number of operations defined on it.
* Menu:
* Geometric operations:: Vector and matrix operations.
* Object transformations:: Transformations of objects